<?php
namespace app\erp_meixingtiyu\controller;

use think\facade\Request;
use app\store\controller\Controller as StoreController;
use app\erp_meixingtiyu\logic\Coach as CoachLogic;

class Coach extends StoreController
{
    public function list()
    {
        $list = (new CoachLogic())->getEmployeeList();
        return $this->renderSuccess($list);
    }

    // 根据id获取单个教练信息
    public function info($employee_id)
    {
        $employee = (new CoachLogic())->getInfoById($employee_id);
        return $this->renderSuccess($employee);
    }

    public function add()
    {
        $params = Request::only([
            'user_id',
            'name',
            'graduated',
            'specialty',
            'brief',
            'image_id',
        ]);
        $coach = (new CoachLogic())->addEmployee($params);
        return $this->renderSuccess($coach, '添加成功');
    }

    public function edit()
    {
        $params = Request::only([
            'employee_id',
            'user_id',
            'name',
            'graduated',
            'specialty',
            'brief',
            'image_id',
        ]);
        $employee = CoachLogic::updateEmployee($params);
        return $this->renderSuccess($employee, '编辑成功');
    }

    // 删除工作人员
    public function del($employee_id)
    {
        (new CoachLogic())->deleteEmployee($employee_id);
        return $this->renderSuccess('删除成功');
    }

    // 获取所有工作人员，在新增/编辑课程时提供选择
    public function all()
    {
        $list = (new CoachLogic)->getAllCoach();
        return $this->renderSuccess($list);
    }
}
